#!/bin/bash

# 查看服务状态脚本

echo "========================================"
echo "  Spring Cloud 服务状态"
echo "========================================"
echo ""

# 检查 Docker 是否运行
if ! docker info > /dev/null 2>&1; then
    echo "❌ Docker 未运行"
    exit 1
fi

echo "📊 容器状态："
docker-compose ps

echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "  服务健康检查："
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"

# 检查 MySQL
echo -n "  MySQL:     "
if docker-compose exec -T mysql mysqladmin ping -h localhost -uroot -proot123456 > /dev/null 2>&1; then
    echo "✅ 运行正常"
else
    echo "❌ 未响应"
fi

# 检查 Nacos
echo -n "  Nacos:     "
if curl -s http://localhost:8848/nacos > /dev/null 2>&1; then
    echo "✅ 运行正常 (http://localhost:8848/nacos)"
else
    echo "❌ 未响应"
fi

# 检查 Sentinel
echo -n "  Sentinel:  "
if curl -s http://localhost:8858 > /dev/null 2>&1; then
    echo "✅ 运行正常 (http://localhost:8858)"
else
    echo "❌ 未响应"
fi

# 检查 Seata
echo -n "  Seata:     "
if curl -s http://localhost:7091 > /dev/null 2>&1; then
    echo "✅ 运行正常 (http://localhost:7091)"
else
    echo "❌ 未响应"
fi

# 检查 Redis
echo -n "  Redis:     "
if docker-compose exec -T redis redis-cli -a redis123456 ping > /dev/null 2>&1; then
    echo "✅ 运行正常"
else
    echo "❌ 未响应"
fi

echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

